
var paths = ReadPaths(GetScriptPath() + "\\exportfile.txt");

var fs = new ActiveXObject("Scripting.FileSystemObject");
var	WSHShell = WScript.CreateObject("WScript.Shell");

var serverPath = GetServerWorkPath()
var scriptPath = GetScriptPath()
var projectName = GetProjectName()

for(i =0; i < paths.length; i++)
{
	var path = paths[i]
	
	path = path.toString().replace(serverPath, scriptPath + "\\" + projectName);
	var re = new RegExp("/","g")
	path = path.toString().replace(re, "\\");

	var folderName = fs.GetParentFolderName(path);
	
	if(!fs.FolderExists(folderName))
	{
		CreateFolders(folderName)
	}
	
	WSHShell.Run("cmd.exe /q /c svn export "+paths[i] + " " + folderName)
}

WScript.Echo("export finish!!!");
WScript.Quit(0);

function CreateFolders(path)
{
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    CreateFolderEx(fso, path)
}

function CreateFolderEx(fso, path)
{
    if(fso.FolderExists(path))
    {
        return
    }

    if(!fso.FolderExists(fso.GetParentFolderName(path)))
    {
        CreateFolderEx(fso, fso.GetParentFolderName(path))
    }

    fso.CreateFolder(path)
}

function GetProjectName()
{
	var scriptPath = GetServerWorkPath()
	var index = scriptPath.toString().lastIndexOf("/");
	return scriptPath.toString().substr(index+1);
}

//获取操作文件列表
function ReadPaths(path)
{
	var retPaths = new Array();
	var fs = new ActiveXObject("Scripting.FileSystemObject");
	if(fs.FileExists(path))
	{
		var a = fs.OpenTextFile(path, 1, false);
		var i = 0;
		while(!a.AtEndOfStream)
		{
			var line = a.ReadLine();
			retPaths[i] = line;
			i= i +1;
		}
		a.Close();
	}
	return retPaths;
}

function GetScriptPath()
{
	var fs = new ActiveXObject("Scripting.FileSystemObject");
	return fs.GetParentFolderName(WScript.ScriptFullName)
}

function GetWorkPath()
{
	var scriptPath = GetScriptPath()
	var index = scriptPath.toString().lastIndexOf("\\");
	return scriptPath.toString().substr(0, index);
}

function GetServerWorkPath()
{
	var path = GetScriptPath() + "\\config.txt";
	var fs = new ActiveXObject("Scripting.FileSystemObject");
	var workPath = ""
	if(fs.FileExists(path))
	{
		var a = fs.OpenTextFile(path, 1, false);
		workPath = a.ReadLine()
		a.Close();
	}
	return workPath;
}
